/**
 * 文件名：userMysql.java
 *
 * 版本信息：
 * 日期：2012-2-9
 * Copyright 足下 Corporation 2012 
 * 版权所有
 *
 */
package com.cafe.database;

import java.sql.DriverManager;
import java.sql.Time;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

/**
 * 
 * @Project：malamute
 * @Title：userMysql
 * @Description：
 * @author：chen
 * @date：2012-2-9 下午01:47:02
 * @version
 * 
 */
public class userMysql {
	public static void main(String[] args) {
		java.util.Date now_start = new java.util.Date();
		long start_time = now_start.getTime();
		int st = 1000;
		String str, info;
		String db = "com.mysql.jdbc.Driver";
		String host = "jdbc:mysql://127.0.0.1/test";
		String user = "root";
		String passwd = "123456";
		Connection con = null;
		try {
			Class.forName(db).newInstance();
		} catch (Exception e) {
			System.out.println("加载驱动失败:" + db);
		}
		try {
			con = (Connection) DriverManager.getConnection(host, user, passwd);
			con.setAutoCommit(false);// 关闭事务自动提交
			for (int i = 1; i <= st; i++) {
				info = "chenuser";
				info = info.concat(java.lang.Integer.toString(i));
				str = "insert into T_CAFE_CUSTOMER (name,username,mobilePhone,email,address,age) values(?,?,?,?,?,?);";
				PreparedStatement pstmt = (PreparedStatement) con
						.prepareStatement(str);

				pstmt.setString(1, info);
				pstmt.setString(2, info);
				pstmt.setInt(3, i);
				pstmt.setString(4, info);
				pstmt.setString(5, "宁波");
				pstmt.setLong(6, 17);
				pstmt.executeUpdate();
			}
			con.commit();// 语句执行完毕，提交本事务
			con.close();
		} catch (Exception e) {
			System.out.println(e);
		}
		java.util.Date now_end = new java.util.Date();
		long end_time = now_end.getTime();
		long use_time = end_time - start_time;
		System.out.println("<<---本页生成耗时[" + use_time + "]毫秒("
				+ ((double) use_time) / 1000 + "秒)--->>");
		System.out.println("\n<<---共插入记录" + st + "条-->>");
	}
}
